package view;

import model.AndGate;

import java.awt.Graphics;

import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import controller.Controller;

/**
 * AndGate megjelenítéséért felelős osztály
 * JPanel és MouseListener leszármazás és implementálás a kattinthatóságért
 * @author radioactivebee
 *
 */
public class AndGateView extends JPanel implements Paintable, MouseListener, ModelProvider {

	private static final long serialVersionUID = 1L;
	private int x;
	private int y;
	private AndGate andGate;
	public List<InputView> inputViews = new ArrayList<InputView>();
	public OutputView outputView;
	
	public AndGateView(int x, int y, AndGate andGate) {
		super();
		this.x = x;
		this.y = y;
		this.andGate = andGate;
		Integer inNum = andGate.getInputs().size();
		Integer step = 40/inNum-1;
		for (int i = 0; i<inNum; i++){
			inputViews.add(new InputView(x, y+15+i*step, andGate.getInputs().get(i), andGate));
		}
		outputView = new OutputView(x+50, y+25, andGate.getOutput(), this.andGate);
		setBounds(this.x, this.y, 50, 50);
		addMouseListener(this);
	}
	
	@Override
	public void mouseClicked(MouseEvent e){
		if(Controller.verbose){
			System.out.println("andgateview mouse listener invoked");
		}
		Controller.getInstance().blockClicked(this);
	}

	@Override
	public void paint(Graphics g) {
		Image img;
		img = new ImageIcon("img/andgate.png").getImage();
		g.drawImage(img, x, y, null);
		for (Paintable p :  inputViews){
			p.paint(g);
		}
		outputView.paint(g);		
	}

	public AndGate getModel(){
		return andGate;
	}
	
/*	public Integer getX() {
		return x;
	}

	public void setX(Integer x) {
		this.x = x;
	}

	public Integer getY() {
		return y;
	}

	public void setY(Integer y) {
		this.y = y;
	}*/

	@Override
	public void mouseEntered(MouseEvent arg0) {
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
	}

	@Override
	public void mousePressed(MouseEvent arg0) {	
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
	}

	
	
}
